#include <iostream>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include<stdio.h>
#include<string.h>
using namespace std;

//检验文件描述符
int main()
{
    int fd1 = open("myfile1.txt",O_WRONLY|O_CREAT|O_APPEND,0666);
    int fd2 = open("myfile2.txt",O_WRONLY|O_CREAT|O_APPEND,0666);
    int fd3 = open("myfile3.txt",O_WRONLY|O_CREAT|O_APPEND,0666);
    cout<<fd1<<" "<<fd2<<" "<<fd3<<endl;
    dup2(fd3,fd1);
    dup2(fd3,fd2);
    close(fd3);
    char buffer[1024];
    cin>>buffer;
    write(fd1,buffer,strlen(buffer));
    write(fd2,buffer,strlen(buffer));
    int rt = write(fd3,buffer,strlen(buffer));
    cout<<rt<<endl;
    return 0;
}